import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Lobster here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Lobster extends Actor
{
    /**
     * Act - do whatever the Lobster wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int count = 0;
    public void act() 
    {
        move(5);
        getRandomNumber();
        atEdge();
        eat();
    } 
    
    public void eat()
    {
        if (isTouching​(Crab.class)) {
            removeTouching​(Crab.class);
            count++;
            Greenfoot.playSound("slurp.wav");
        }
        if (count == 1) {
            World w =getWorld();
            GreenfootImage bg = w.getBackground();
            bg.setFont(new Font(true,true,150));
            bg.setColor(new Color(255,0,0));
            bg.drawString("失败！" ,200 ,300);
            Greenfoot.stop();
        }
    }
    
    public void getRandomNumber()
    { 
        if (Greenfoot.getRandomNumber​(100)<40) {
            turn(Greenfoot.getRandomNumber​(30)-15);
        }
        
    }
    
    public void atEdge()
    {
        if (isAtEdge()){
            turn(15);       
        }
    }   
}
